package com.pinyougou.manager.controller;

import java.util.List;

import org.apache.zookeeper.data.Id;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;

import entity.PageResult;
import entity.Result;


@RestController
@RequestMapping("/brand")
public class BrandCOntroller {
	
	@Reference
	private BrandService brandService;
	
	@RequestMapping("/findAll")
	public List<TbBrand> findAll(){
		
		 return brandService.findAll();
	}
	
	@RequestMapping("/findPage")
	public PageResult findPage(@RequestParam("page")int pageNum,@RequestParam("size")int pageSize){
		
		PageResult findPage = brandService.findPage(pageNum, pageSize);
		
		return findPage;
	}
	
	
	@RequestMapping("/add")
	public Result add(@RequestBody TbBrand tbBrand){
		try {
			brandService.add(tbBrand);
			return new Result(true, "增加成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "增加失败");
		}
	}
	
	@RequestMapping("/findOne")
	public TbBrand findOne(long id){
		return brandService.findOne(id);
		
	}
	
	@RequestMapping("/update")
	public Result update(@RequestBody TbBrand tbBrand){
		try {
			brandService.update(tbBrand);
			return new Result(true, "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "修改失败");
		}
	}
	
	@RequestMapping("/deleBrand")
	public Result deleBrand(long[] ids){
		try {
			brandService.deleBrand(ids);
			return new Result(true, "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "删除失败");
		}
	}
	@RequestMapping("/serch")
	public PageResult serch(@RequestBody TbBrand brand,int page,int size){
		
		return brandService.findPage(brand, page, size);
		
	}
}
